//
//  JiJinTypeVC.m
//  BaseProject
//
//  Created by hundredsandc on 2017/10/30.
//  Copyright © 2017年 hundredsandc. All rights reserved.
//

#import "JiJinTypeVC.h"
#import "JiJinTypeCollectionViewCell.h"
#import "Masonry.h"
#import "WEBViewController.h"

@interface JiJinTypeVC ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
@property (nonatomic,strong)UICollectionView *collectionView;
@property (nonatomic,strong)UICollectionViewFlowLayout *flowLayOut;
@property (nonatomic,strong)NSArray *iconNameArr;
@property (nonatomic,strong)NSArray *iconPathArr;
@end

@implementation JiJinTypeVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"集锦分类";
    [self.view addSubview:self.collectionView];
    [self addConstraint];
}
-(void)addConstraint{
    WS(ws);
    [_collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(ws.view);
        make.bottom.mas_equalTo(ws.view).with.offset(-64);
        make.width.mas_equalTo(SCREEN_WIDTH);
        make.left.equalTo(ws.view);
    }];
}
#pragma mark - collection
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 9;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    JiJinTypeCollectionViewCell *item = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([JiJinTypeCollectionViewCell class]) forIndexPath:indexPath];
   
    
        [item customImageUrlStr:self.iconPathArr[indexPath.item] title:self.iconNameArr[indexPath.item]];
    
    return item;
}
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    return CGSizeMake(100, 80);
}


-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
    return UIEdgeInsetsMake(30, 30, 30, 30);
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    NSLog(@"11");//全部：0，NBA：1，英超：4，CBA：2，西甲：6，中超：9，德甲：3，意甲：5， 欧冠：8，法甲：7
    NSInteger type;
    if (indexPath.item==0) {
        type=9;
    }else if (indexPath.item==1){
        type=4;
    }else if (indexPath.item==2){
        type=6;
    }else if (indexPath.item==3){
        type=8;
    }else if (indexPath.item==4){
        type=7;
    }else if (indexPath.item==5){
        type=3;
    }else if (indexPath.item==6){
        type=5;
    }else if (indexPath.item==7){
        type=2;
    }else {
        type=9;
    }
    if (self.selectBlock) {
        self.selectBlock(type);
    }
    [self.navigationController popViewControllerAnimated:YES];

    
}
-(UICollectionView *)collectionView{
    if (!_collectionView) {
        _collectionView = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:self.flowLayOut];
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
    
        _collectionView.backgroundColor = [UIColor whiteColor];
        
        [_collectionView registerNib:[UINib nibWithNibName:NSStringFromClass([JiJinTypeCollectionViewCell class]) bundle:nil] forCellWithReuseIdentifier:NSStringFromClass([JiJinTypeCollectionViewCell class])];
    }
    return _collectionView;
}
-(UICollectionViewFlowLayout *)flowLayOut{
    if (!_flowLayOut) {
        _flowLayOut = [[UICollectionViewFlowLayout alloc] init];
        
        _flowLayOut.minimumInteritemSpacing = 9;
        _flowLayOut.minimumLineSpacing = 15;
        [_flowLayOut setScrollDirection:UICollectionViewScrollDirectionVertical];
        
    }
    return _flowLayOut;
}
-(NSArray *)iconNameArr{
    if (!_iconNameArr) {
        _iconNameArr = @[@"亚冠",@"英超",@"西甲",@"欧冠",@"法甲",@"德甲",@"意甲",@"CBA",@"中超"];
    }
    return _iconNameArr;
}
-(NSArray *)iconPathArr{
    if (!_iconPathArr) {
        _iconPathArr = @[@"yaguan",@"yingchao",@"xijia",@"ouguan",@"fajia",@"dejia",@"yijia",@"cba",@"zhongchao"];
        
    }
    return _iconPathArr;
}

@end
